DIFF

Section: User Commands (1)
Updated: 24 January 1991
Index Return to Main Contents
 

NAME

diff - GNU diff, display line-by-line differences between files, including binary files  

SYNOPSIS

diff [ options ] filename1 filename2
diff [ options ] directory1 directory2  

WARNING

This manual page is updated only occasionally, because the GNU project does not use nroff.  

DESCRIPTION

This version of diff provides all the features of BSD's diff. It has the following additional features.

An input file may end in a non-newline character. If so, its last line is called an incomplete line and is distinguished on output from a full line. In the default, -c, and -u output styles, an incomplete output line is followed by a diagnostic line that starts with \. With -n, an incomplete line is output without a trailing newline. Other output styles (-D, -e, -f) cannot represent an incomplete line, so they pretend that there was a newline, and -e and -f also print an error message.

For example, suppose F and G are one-byte files that contain just `f' and `g', respectively. Then `diff F G' outputs

1c1
< f
\ No newline at end of file
---
> g
\ No newline at end of file

(The exact diagnostic message may differ, e.g. for non-English locales.) `diff -n F G' outputs the following without a trailing newline:

d1 1
a1 1
g

`diff -e F G' sends two diagnostics to standard error and the following to standard output:

1c
g
.

A file is considered to be text if its first characters are all in the ISO 8859 character set; BSD's diff uses ASCII.  

OPTIONS

GNU diff has the following additional options:
-a
Always treat files as text and compare them line-by-line, even if they do not appear to be text.
-B
Ignore changes that just insert or delete blank lines.
-C #
Request -c format and specify number of context lines.
-F regexp
In context format, for each unit of differences, show some of the last preceding line that matches the specified regexp.
-H
Use heuristics to speed handling of large files that have numerous scattered small changes. The algorithm becomes asymptotically linear for such files!
-I regexp
Ignore changes that just insert or delete lines that match the specified regexp.
-L label
Use the specified label in file header lines output by the -c option. This option may be given zero, one, or two times, to affect neither label, just the first file's label, or both labels. A file's default label is its name, a tab, and its modification date.
-N
In directory comparison, if a file is found in only one directory, treat it as present but empty in the other directory.
-p
equivalent to -c -F'^[_a-zA-Z]'. This is useful for C code because it shows which function each change is in.
-T
Print a tab rather than a space before the text of a line in normal or context format. This causes the alignment of tabs in the line to look normal.
-u [#]
Produce unified style output with # context lines (default 3). This style is like -c, but it is more compact because context lines are printed only once. Lines from just the first file are marked '-'; lines from just the second file are marked '+'.
 

SEE ALSO

diff3(1)


 

Index

NAME
SYNOPSIS
WARNING
DESCRIPTION
OPTIONS
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 08:54:20 GMT, February 14, 2025